package com.gyms.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gyms.R;
import com.classic.okhttp.beans.HVCitiesBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * ltx on 2016/11/2 10:30
 * 城市列表适配器
 */
public class CityAdapter extends BaseAdapter {
    private List<HVCitiesBean> mHVCitiesBeens;
    private Context mContext;
    private ViewHolder mViewHolder;

    public CityAdapter(Context mContext) {
        this.mContext = mContext;
    }


    @Override
    public int getCount() {
        return null != mHVCitiesBeens ? mHVCitiesBeens.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return mHVCitiesBeens.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (null == convertView) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.ll_city_item, parent, false);
            mViewHolder=new ViewHolder(convertView);
            convertView.setTag(mViewHolder);
        }
        mViewHolder= (ViewHolder) convertView.getTag();
        HVCitiesBean mHvCityBean=mHVCitiesBeens.get(position);
        initData(mHvCityBean);
        return convertView;
    }

    private void initData(HVCitiesBean mHvCityBean) {
        mViewHolder.mTvCity.setText(mHvCityBean.getName());
    }

    public void setHVCitiesBeens(List<HVCitiesBean> HVCitiesBeens) {
        mHVCitiesBeens = HVCitiesBeens;
    }

    static class ViewHolder {
        @BindView(R.id.tv_city)
        TextView mTvCity;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
